const express = require('express')
const router = express.Router()

const sysMenuController = require('../controller/SysMenuController')

/**
 * @api {get} /api/v1/menu/list 获取菜单列表
 * @apiDescription /api/v1/menu/list
 * @apiName list
 * @apiGroup SysMenu
 * @apiParam {number} [type]           查询类型   1 全部菜单列表；2全部菜单列表-按children结构返回；3 不包含操作权限
 * @apiParam {number} [page]         当前页
 * @apiParam {number} [pageSize]     分页大小
 * @apiParam {number} [menuId]       菜单id
 * @apiParam {string} [menuName]     菜单名称
 * @apiParam {date} [createdAt]     创建时间
 * @apiSampleRequest /api/v1/menu/list
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysMenu[]} data 菜单信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *      "code" : 200,
 *      "data" : [
 *        {
            "menuId": 3,
            "menuName": "系统工具",
            "parentId": 0,
            "orderNum": 3,
            "url": "#",
            "target": "",
            "menuType": "M",
            "visible": "0",
            "isRefresh": "1",
            "perms": "",
            "icon": "fa fa-bars",
            "createdBy": "admin",
            "createdAt": "2023-08-23T09:16:22.000Z",
            "updatedBy": "",
            "updatedAt": null,
            "remark": "系统工具目录"
          }
 *      ],
 *      "message" : "请求成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/list', sysMenuController.menuList)

/**
 * @api {get} /api/v1/menu/:id 根据id查询菜单信息
 * @apiDescription /api/v1/menu/:id
 * @apiName getMenuById
 * @apiGroup SysMenu
 * @apiParam {number} id 菜单id
 * @apiSampleRequest /api/v1/menu/:id
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysMenu} data 菜单信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" : {
            "menuId": 3,
            "menuName": "系统工具",
            "parentId": 0,
            "orderNum": 3,
            "url": "#",
            "target": "",
            "menuType": "M",
            "visible": "0",
            "isRefresh": "1",
            "perms": "",
            "icon": "fa fa-bars",
            "createdBy": "admin",
            "createdAt": "2023-08-23T09:16:22.000Z",
            "updatedBy": "",
            "updatedAt": null,
            "remark": "系统工具目录"
          },
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/:id', sysMenuController.selectMenuById)

/**
 * @api {post} /api/v1/menu/add 添加菜单
 * @apiDescription /api/v1/menu/add
 * @apiName add
 * @apiGroup SysMenu
 * @apiBody {string} [menuName]    菜单名称
 * @apiBody {string} [parentId]    菜单父级
 * @apiBody {number} [orderNum]    排序
 * @apiBody {string} [url]          菜单地址
 * @apiBody {string} [target]       菜单打开方式
 * @apiBody {string} [menuType]    菜单类型
 * @apiBody {string} [visible]      菜单状态
 * @apiBody {string} [isRefresh]   是否刷新
 * @apiBody {string} [perms]        权限标识
 * @apiBody {string} [icon]         菜单图标
 * @apiBody {string} [remark]       备注
 * @apiSampleRequest /api/v1/menu/add
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {boolean} data 执行结果
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *      "code" : 200,
 *      "data" : true,
 *      "message" : "请求成功",
 *  }
 * @apiVersion v1.0.0
 */
router.post('/add', sysMenuController.addMenu)

/**
 * @api {put} /api/v1/menu/update 更新菜单
 * @apiDescription /api/v1/menu/update
 * @apiName update
 * @apiGroup SysMenu
 * @apiBody {string} menuId        菜单id
 * @apiBody {string} [menuName]    菜单名称
 * @apiBody {string} [parentId]    菜单父级
 * @apiBody {number} [orderNum]    排序
 * @apiBody {string} [url]          菜单地址
 * @apiBody {string} [target]       菜单打开方式
 * @apiBody {string} [menuType]    菜单类型
 * @apiBody {string} [visible]      菜单状态
 * @apiBody {string} [isRefresh]   是否刷新
 * @apiBody {string} [perms]        权限标识
 * @apiBody {string} [icon]         菜单图标
 * @apiSampleRequest /api/v1/menu/update
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {boolean} data 执行结果
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *      "code" : 200,
 *      "data" : true,
 *      "message" : "请求成功",
 *  }
 * @apiVersion v1.0.0
 */
router.put('/update', sysMenuController.updateMenu)


/**
 * @api {delete} /api/v1/menu/delete 删除菜单
 * @apiDescription /api/v1/menu/delete
 * @apiName delete
 * @apiGroup SysMenu
 * @apiBody {number} id 菜单id
 * @apiSampleRequest /api/v1/menu/delete
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {boolean} data 执行结果
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" : true,
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.delete('/delete', sysMenuController.deleteMenu)

module.exports = router